package top.healthylife.gateway.platform.td.api.api.monitor;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import top.healthylife.gateway.core.service.ParentFace;
import top.healthylife.gateway.dto.annotation.ApiServiceExplain;
import top.healthylife.gateway.platform.td.api.utils.TdUtils;
import top.healthylife.gateway.platform.td.dto.monitor.addmonitor.req.TdReqAddMonitorDto;
import top.healthylife.gateway.platform.td.dto.monitor.addmonitor.res.TdResAddMonitorDto;

import java.time.ZoneOffset;

/**
 * @author GaoZeXi
 * @date 2021/7/20 13:19
 */
@Slf4j
@Service
@ApiServiceExplain(price = 20, apiName = "直接添加监控", info = "个人贷中监控服务是信贷云产品面向信贷机构新增的贷中管理服务，帮助平台对已放款的借款人进行监控， 当借款人在同盾其他合作平台出现逾期记录、新增借贷或者经济法律纠纷时，同盾识别后及时通知平台，帮 助平台提早防范借款人信用恶化风险。")
public class TdAddMonitorApi implements ParentFace<TdReqAddMonitorDto, TdResAddMonitorDto> {

    static final String URL = "/postloan/monitor.specific/v5";
    static final String REQUEST_METHOD = "POST";

    @Override
    public TdResAddMonitorDto execute(TdReqAddMonitorDto dto) {
        long startTime = dto.getStartTime().atStartOfDay(ZoneOffset.ofHours(8)).toInstant().toEpochMilli();
        long endTime = dto.getEndTime().atStartOfDay(ZoneOffset.ofHours(8)).toInstant().toEpochMilli();
        dto.setBeginScanTime(startTime).setEndScanTime(endTime);
        JSONObject jsonObject = TdUtils.tongDunHttpRequest(dto, URL, REQUEST_METHOD);
        return jsonObject.toJavaObject(TdResAddMonitorDto.class);
    }
}
